import { useReducer } from "react";
type InitiaState = {
  visible: boolean;
  formData: any;
  id: number;
};
enum ActionState {
  SET_VISIBLE = "setVisible",
  SET_FORM_DATA = "setFormData",
  SET_ID = "setId",
}

type Action = { type: ActionState; payload?: any };
type Reducer = React.Reducer<InitiaState, Action>;
const reducer: Reducer = (state, action) => {
  switch (action.type) {
    case ActionState.SET_VISIBLE: {
      return {
        ...state,
        visible: action.payload,
      };
    }
    case ActionState.SET_FORM_DATA: {
      return {
        ...state,
        formData: action.payload,
      };
    }
    case ActionState.SET_ID: {
      return {
        ...state,
        id: action.payload,
      };
    }
    default: {
      return {
        ...state,
      };
    }
  }
};
const initState: InitiaState = {
  visible: false,
  formData: {},
  id: 0,
};
const usePicClassifyStore = () => {
  const [state, dispatch] = useReducer<Reducer>(reducer, initState);
  return {
    state,
    dispatch,
    ActionState,
  };
};

export default usePicClassifyStore;
